//package Demo6;
//
//class Student implements  Comparable<Student>{
//    public String name;
//    public int age;
//
//    public Student(String name, int age) {
//        this.name = name;
//        this.age = age;
//    }
//
//    @Override
//    public String toString() {
//        return "Student{" +
//                "name='" + name + '\'' +
//                ", age=" + age +
//                '}';
//    }
//
//
//    @Override
//    public int compareTo(Student student) {
//        if(this.age > student.age){
//            return 1;
//        }
//        else if(this.age == student.age)
//        {
//            return 0;
//        }
//        else{
//            return -1;
//        }
//    }
//}
//public class Test {
//    public static void main(String[] args) {
//
//    }
//    public static void main1(String[] args) {
//        int a = 10;
//        int b = 20;
//        System.out.println(a > b);  // false
//
//        Student student1 = new Student("张三",10);
//        Student student2 = new Student("李四",10);
//        System.out.println(student1.compareTo(student2));
//    }
//
//}
//
//
//
//





package Demo6;

import java.sql.Array;
import java.sql.SQLOutput;
import java.util.Arrays;
import java.util.Comparator;

class Student implements Comparable<Student>{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        return this.age - o.age;
    }
}
class AgeComparator implements Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        return o1.age - o2.age;
    }
}
class NameComparatoe implements Comparator<Student>
{
    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}
public class Test {
    public static void main(String[] args) {
//        Student student1 = new Student("张三",10);
//        Student student2 = new Student("李四",10);
//        AgeComparator ageComparator = new AgeComparator();
//        System.out.println(ageComparator.compare(student1,student2));

        Student[] students = new Student[3];
        students[0] = new Student("张三",220);
        students[1] = new Student("李四",200);
        students[2] = new Student("王五",30);
        System.out.println("排序前" + Arrays.toString(students));
        Arrays.sort(students);
        System.out.println("排序后"+ Arrays.toString(students));
    }


    public static void main2(String[] args) {
        int a = 10;
        int b = 20;
        System.out.println(a > b);  // false

        Student student1 = new Student("张三",10);
        Student student2 = new Student("李四",10);
        AgeComparator ageComparator = new AgeComparator();
//        System.out.println(student1.age,student2.age);


    }

}




